package com.kakaxi.mybilibili.module.home.live.view;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;

import com.kakaxi.mybilibili.R;
import com.kakaxi.mybilibili.adapter.LiveRoomMedalRankRecyAdapter;
import com.kakaxi.mybilibili.base.BaseFragment;
import com.kakaxi.mybilibili.module.home.live.presenter.LiveRoomMedalRankPresenter;
import com.kakaxi.mybilibili.bean.LiveRoomMedalRankItemBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 直播间粉丝榜碎片类
 * Created by kakaxi on 16/11/9.
 */

public class LiveRoomMedalRankFragment extends BaseFragment implements ILiveRoomMedalRankView {

    /** 刷新控件 **/
    @BindView(R.id.srl_common_fragment)
    SwipeRefreshLayout mMedalRankRefresh;

    /** 数据列表 **/
    @BindView(R.id.recv_common_fragment)
    RecyclerView mMedalRankRecyView;

    /** 礼物排行榜列表适配器 **/
    private LiveRoomMedalRankRecyAdapter mLiveRoomMedalRankAdapter;

    /** 控制层 **/
    private LiveRoomMedalRankPresenter mPresenter;

    public static LiveRoomMedalRankFragment newInstance() {
        LiveRoomMedalRankFragment liveRoomMedalRankFragment = new LiveRoomMedalRankFragment();
        return liveRoomMedalRankFragment;
    }

    @Override
    protected int getContentViewId() {
        return R.layout.fragment_common_recycler;
    }

    @Override
    protected void setupViews(ViewGroup viewGroup) {
        ButterKnife.bind(this, viewGroup);
        // 初始化列表控件
        mMedalRankRecyView.setLayoutManager(new LinearLayoutManager(getContext()));
        // 初始化刷新控件
        mMedalRankRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                mPresenter.refreshMedalRankData(0);
            }
        });
    }

    @Override
    protected void initData() {
        mPresenter = new LiveRoomMedalRankPresenter(this);
        mPresenter.initMedalRankData(0);
    }

    @Override
    public void showGiftTopData(List<LiveRoomMedalRankItemBean> medalRankItemBeanList) {
        if (mLiveRoomMedalRankAdapter == null) {
            mLiveRoomMedalRankAdapter = new LiveRoomMedalRankRecyAdapter(medalRankItemBeanList);
            mMedalRankRecyView.setAdapter(mLiveRoomMedalRankAdapter);
        } else {
            mLiveRoomMedalRankAdapter.setNewData(medalRankItemBeanList);
        }
    }

    @Override
    public boolean isConnectNetwork() {
        return false;
    }

    @Override
    public int getConnectType() {
        return 0;
    }

    @Override
    public void showLoading() {
        mMedalRankRefresh.setRefreshing(true);
    }

    @Override
    public void hideLoading() {
        mMedalRankRefresh.setRefreshing(false);
    }

    @Override
    public void showEmptyView() {

    }

    @Override
    public void showMessage(String message) {
        toastHandler(message);
    }
}
